from fastapi import FastAPI
from starlette.config import Config

from controller import user, app as system
from register import golbal_exception_handlers
from register.cors import register_cors
from register.golbal_exception_handlers import register_exception_handler
from register.gzip import register_gzip
from register.json_result import register_json_result

config = Config(".env")  # 解析 .env 文件中的环境变量

ENVIRONMENT = config("ENVIRONMENT")  # 获取当前环境名称
SHOW_DOCS_ENVIRONMENT = ("local", "staging")  # 允许显示文档的环境名称列表

app_configs = {"title": "My Cool API"}
if ENVIRONMENT not in SHOW_DOCS_ENVIRONMENT:
    app_configs["openapi_url"] = None  # 将文档的 url 设置为 null

app = FastAPI(**app_configs)

# register_redis(app)
register_cors(app)
register_json_result(app)
register_exception_handler(app)
register_gzip(app)
# app = FastAPI(debug=True)

app.include_router(user.router)
app.include_router(system.router)


@app.get("/")
async def root():
    return {"message": "Hello World"}


@app.get("/hello/{name}")
async def say_hello(name: str):
    return {"message": f"Hello {name}"}
